# -*- coding: utf-8 -*-
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

mx_eyelink_is_connected = binder_py('mx_eyelink_is_connected')
mx_eyelink_is_connected.mx_c.headers = ['<eyelink.h>','"mex.h"']
mx_eyelink_is_connected.mx_c.code = '''

INT16 _main( void )
{
    return eyelink_is_connected( ); 
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    
    /* Verify input arguments. */
    if(nrhs > 0 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
       
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);    
    *status = (double ) _main( );
    
    return;
    
}


'''

mx_eyelink_is_connected.mx_c.mdoc = \
'''function [ status, code ] = mx_eyelink_is_connected( )
%MX_eyelink_is_connected Checks whether the connection to the tracker is alive.
% 
% Remarks:
% Call this routine during loops and wherever the experiment might lock up if 
% the tracker is shut down. Exit the experiment (by terminating loops and 
% returning from all calls) if this returns 0.
% Returns:
% 0 if link closed.
% -1 if simulating connection.
% 1 for normal connection.
% 2 for broadcast connection (NEW for v2.1 and later).
%
'''
mx_eyelink_is_connected.write_c()
mx_eyelink_is_connected.write_m()
mx_eyelink_is_connected.compile()
mx_eyelink_is_connected.write_sh()

